package ldk.util.logger;

import android.content.Context;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import static org.hamcrest.CoreMatchers.is;

/**
 * Created by ldkxingzhe@163.com on 2017/5/26.
 */
@RunWith(MockitoJUnitRunner.class)
public class MockitoSample {
    private static final String FAKE_STRING = "HELLO WORLD";

    @Mock
    Context mMockContext;

    @Test
    public void readStringFromContext_LocalizedString(){
        // Given a mocked Context injected into the object under test...
        Mockito.when(mMockContext.getString(R.string.hello_word))
                .thenReturn(FAKE_STRING);
        ClassUnderTest test = new ClassUnderTest(mMockContext);
        String helloWorld = test.getHelloWorld();
        Assert.assertThat(helloWorld, is(FAKE_STRING));
        System.out.println("哈哈");
    }

    private class ClassUnderTest {
        private Context mContext;

        public ClassUnderTest(Context context){
            mContext = context;
        }

        public String getHelloWorld(){
            return mContext.getString(R.string.hello_word);
        }
    }
}
